﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class SceneLoader : MonoBehaviour
{
    public GameObject eventObj;
    public Button btnA;
    public Button btnB;

    public Animator animator;

    // Start is called before the first frame update
    void Start()
    {
        GameObject.DontDestroyOnLoad(gameObject);
        GameObject.DontDestroyOnLoad(eventObj);

    }

    // Update is called once per frame
    void Update()
    {
        
    }

    IEnumerator LoadScene(string sceneName)
    {
        animator.SetBool("FadeIn", false);
        animator.SetBool("FadeOut", true);
        
        yield return new WaitForSeconds(1);

        AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneName);
        asyncOperation.completed += OnSceneLoad;
    }

    private void OnSceneLoad(AsyncOperation obj)
    {
        animator.SetBool("FadeIn", true);
        animator.SetBool("FadeOut", false);
    }

    public void LoadSceneB()
    {
        StartCoroutine(LoadScene("Scenes/TransScenes/SceneB"));
    }

    public void LoadSceneA()
    {
        StartCoroutine(LoadScene("Scenes/TransScenes/SceneA"));
    }
}
